﻿using Anke.SHManage.MSSQLDAL.TJDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class TJ_FLHZModeWebForm : System.Web.UI.Page
    {
        private string reportName;
        protected void Page_Load(object sender, EventArgs e)
        {


            if (!IsPostBack)
            {
                InitPage();
            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();
            
        }
        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 07:30:00");
            this.EndDate.Text = DateTime.Now.ToString("yyyy-MM-dd 07:30:00");
            reportName = Request.QueryString["ReportName"];
            ViewState["reportName"] = reportName;
            BindReportDataSource();
        }
        protected void BindReportDataSource()
        {
            DateTime beginTime = Convert.ToDateTime(this.StartDate.Text);
            DateTime endTime = Convert.ToDateTime(this.EndDate.Text);
            //string centerID = Convert.ToString(this.Center.Text);
            string stationID = (this.Station.Text).ToString();
            string doctor = Convert.ToString(this.Doctor.Text);
            string driver = Convert.ToString(this.Driver.Text);
            string stretcherBearers = Convert.ToString(this.StretcherBearers.Text);
            //string doctorworkcode = Convert.ToString(this.DoctorWorkCode.Text);
            //string driverworkcode = Convert.ToString(this.DriverWorkCode.Text);
            //string stretcherBearersworkcode = Convert.ToString(this.StretcherBearersWorkCode.Text);
            string start1 = beginTime.ToString();
            string end1 = endTime.ToString();
            //string type1 = (this.Type.Value).ToString();

            this.ReportViewer1.LocalReport.DataSources.Clear();
            //this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/TJ_JJZXGRYWKSS.rdlc");
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("startTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("endTime", end1);
            Microsoft.Reporting.WebForms.ReportParameter sb = new Microsoft.Reporting.WebForms.ReportParameter("stretcherBearers", stretcherBearers);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed ,sb});
            TJDAL dal = new TJDAL();
            //this.Page.Title = "医疗急救中心业务款实收统计表";
            //DataTable dt = dal.Get_TJ_JJZXGRYWKSS( beginTime,  endTime,  stationID,  driver,  doctor,  stretcherBearers,
            // driverworkcode, doctorworkcode, stretcherBearersworkcode, centerID);
            //this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_JJZXGRYWKSS", dt));
            switch (reportName)
            {
                //case "TJ_JJZXGRYWKSS.rdlc":
                //    this.Page.Title = "医疗急救中心业务款实收统计表";
                //    DataTable dt = dal.Get_TJ_JJZXGRYWKSS( beginTime,  endTime,  stationID,  driver,  doctor,  stretcherBearers);
                //    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_JJZXGRYWKSS", dt));
                //    break;
                case "TJ_FLHZ.rdlc":
                    this.Page.Title = "上海市松江区急救中心收入分类汇总表";
                    DataTable dt1 = dal.Get_TJ_FLHZ(beginTime, endTime, stationID,doctor,driver,stretcherBearers);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_FLHZ", dt1));
                    break;
                default:
                    break;
            }

            this.ReportViewer1.LocalReport.Refresh();
        }
    }
}